﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RattlerRace;

namespace RattlerRaceGUI
{
    /// <summary>
    /// Dizajn - Denis Jakoša
    /// </summary>
    public partial class RattlerHighScores : Form
    {
        public RattlerHighScores()
        {
            InitializeComponent();
            fillScoreBoard();
            //updateHighScores();
        }

        /// <summary>
        /// Napolni kontrole s podatki. Za vsak del je 5 najboljših rezultatov. Kontrole so nastavljene dinamično.
        /// Denis Jakoša
        /// </summary>
        private void fillScoreBoard()
        {
            //Scoreboard scoreBoard = new Scoreboard();

            ScoreTextHandler.prepareForScoreFill();

            setLabelsHallOfFame(groupBox1.Controls.OfType<Label>().ToList(), ScoreTextHandler.HallOfFame);
            setLabelsToday(groupBox2.Controls.OfType<Label>().ToList(), ScoreTextHandler.Today);

            ScoreTextHandler.refill();
        }

        private void updateScoreBoard(List<Points> hallOfFame, List<Points> today)
        {
            Scoreboard scoreBoard = new Scoreboard();
            setLabelsHallOfFame(groupBox1.Controls.OfType<Label>().ToList(), hallOfFame);
            setLabelsToday(groupBox2.Controls.OfType<Label>().ToList(), today);
        }

        /// <summary>
        /// Prikaže najboljše točke vseh časov.
        /// Denis Jakoša
        /// </summary>
        /// <param name="labels"></param>
        /// <param name="hallOfFamePoints"></param>
        private void setLabelsHallOfFame(List<Label> labels, List<Points> hallOfFamePoints)
        {
            /* TESTNI PODATKI --- TESTNI PODATKI */
            //hallOfFamePoints.Add(new Points("Denis", 157));
            /*hallOfFamePoints.Add(new Points("Denis", 144));
            hallOfFamePoints.Add(new Points("Denis", 126));
            hallOfFamePoints.Add(new Points("Denis", 121));
            hallOfFamePoints.Add(new Points("Denis", 101));
            hallOfFamePoints.Add(new Points("Denis", 85));*/
            /* TESTNI PODATKI --- TESTNI PODATKI */


            int maxScores = 5;
            int scoresNr = 0;
            int playerIndex = 0;

            if (hallOfFamePoints.Count > 5) scoresNr = 5;
            else scoresNr = hallOfFamePoints.Count;

            for (int i = maxScores - 1; i >= maxScores - scoresNr; i--)
            {
                labels[i * 2].Text = hallOfFamePoints[playerIndex].Player;
                labels[i * 2 + 1].Text = hallOfFamePoints[playerIndex].CurrentPoints.ToString();
                playerIndex++;
            }

            

            for (int i = 0; i < labels.Count - 2 * scoresNr; i = i + 2)
            {
                labels[i].Visible = false;
                labels[i + 1].Visible = false;
            }
        }

        /// <summary>
        /// Prikaže dnevne točke.
        /// Denis Jakoša
        /// </summary>
        /// <param name="labels"></param>
        /// <param name="todayPoints"></param>
        private void setLabelsToday(List<Label> labels, List<Points> todayPoints)
        {
            /* TESTNI PODATKI --- TESTNI PODATKI */
            /*todayPoints.Add(new Points("Denis", 127));
            todayPoints.Add(new Points("Denis", 125));
            todayPoints.Add(new Points("Denis", 120));*/
            /* TESTNI PODATKI --- TESTNI PODATKI */

            int maxScores = 5;
            int scoresNr = 0;
            int playerIndex = 0;

            if (todayPoints.Count > 5) scoresNr = 5;
            else scoresNr = todayPoints.Count;

            for (int i = maxScores - 1; i >= maxScores - scoresNr; i--)
            {
                labels[i * 2].Text = todayPoints[playerIndex].Player;
                labels[i * 2 + 1].Text = todayPoints[playerIndex].CurrentPoints.ToString();
                playerIndex++;
            }

            for (int i = 0; i < labels.Count - 2 * scoresNr; i = i + 2)
            {
                labels[i].Visible = false;
                labels[i + 1].Visible = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Scoreboard.clearScores();

            GUI.Sth.clearAll();
            fillScoreBoard();
            //updateHighScores();
        }

        /*private void updateHighScores()
        {
            //Hall of fame
            label3.Text = ScoreTextHandler.HallOfFame[0].CurrentPoints.ToString();
            label4.Text = ScoreTextHandler.HallOfFame[0].Player;

            label6.Text = ScoreTextHandler.HallOfFame[1].CurrentPoints.ToString();
            label5.Text = ScoreTextHandler.HallOfFame[1].Player;

            label8.Text = ScoreTextHandler.HallOfFame[2].CurrentPoints.ToString();
            label7.Text = ScoreTextHandler.HallOfFame[2].Player;

            label10.Text = ScoreTextHandler.HallOfFame[3].CurrentPoints.ToString();
            label9.Text = ScoreTextHandler.HallOfFame[3].Player;

            label12.Text = ScoreTextHandler.HallOfFame[4].CurrentPoints.ToString();
            label11.Text = ScoreTextHandler.HallOfFame[4].Player;

            //Today
            label22.Text = ScoreTextHandler.Today[0].CurrentPoints.ToString();
            label21.Text = ScoreTextHandler.Today[0].Player;

            label20.Text = ScoreTextHandler.Today[1].CurrentPoints.ToString();
            label19.Text = ScoreTextHandler.Today[1].Player;

            label18.Text = ScoreTextHandler.Today[2].CurrentPoints.ToString();
            label17.Text = ScoreTextHandler.Today[2].Player;

            label16.Text = ScoreTextHandler.Today[3].CurrentPoints.ToString();
            label15.Text = ScoreTextHandler.Today[3].Player;

            label14.Text = ScoreTextHandler.Today[4].CurrentPoints.ToString();
            label13.Text = ScoreTextHandler.Today[4].Player;
        }*/
    }
}
